import axios from 'axios'

const ax = axios.create({
  baseURL: 'http://localhost/wp-json/wp/v2',
  timeout: 30000,
  withCredentials: false
})

export default {
  getPost: (params: { id: number }) =>
    ax.get(`/posts/${params.id}?_embed=true`),
  getPage: (params: { id: number }) =>
    ax.get(`/pages/${params.id}`),
  getCategoryPostsById: (params: { categories: number; page: number }) =>
    ax.get('/posts?_embed=true', { params }),
  getCategory: () => ax.get('/categories?parent=0&orderby=id&exclude=5'),
  getPostsByCategory: (params: {
    _embed?: boolean
    categories: number
  }) => ax.get('/posts', { params }),
  getMediaByCategory: (params: { categories: number }) =>
    ax.get('/media', { params }),
  postComment: (data: { post: number; author_name: string; content: string }) =>
    ax.post('/comments', data)
}
